package com.gyms.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.gyms.R;

import java.util.ArrayList;

import click.OnRecyclerViewItemClick;

/**
 * Created by admin on 17/3/29.
 * 筛选框 所有运动项目适配器
 */

public class SelectAdapter extends RecyclerView.Adapter<SelectAdapter.SelectSportViewHolder>{
    private ArrayList<String> mSelectDataStrs;
    private Context mContext;

    private OnRecyclerViewItemClick mOnRecyclerViewItemClick;//自定义OnitemClick

    private int mSelectPos=0;//选中的位置
    public SelectAdapter(Context mContext){
       this.mContext=mContext;
    }

    @Override
    public SelectSportViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View mContentView= LayoutInflater.from(mContext).inflate(R.layout.select_sport_item,parent,false);
        SelectSportViewHolder mViewHolder=new SelectSportViewHolder(mContentView);
        return mViewHolder;
    }

    @Override
    public void onBindViewHolder(SelectSportViewHolder holder, final int position) {
        String mSingleStr=mSelectDataStrs.get(position);
        holder.mTvSportName.setText(mSingleStr);
        if(position==mSelectPos){//选中设置颜色为蓝色
            holder.mTvSportName.setTextColor(mContext.getResources().getColor(R.color.c_0396EB));
        }else{
            holder.mTvSportName.setTextColor(mContext.getResources().getColor(R.color.c_333333));
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {//设置OnItemClick
            @Override
            public void onClick(View v) {
                if(null!=mOnRecyclerViewItemClick){//自定义onItemCLick
                    mOnRecyclerViewItemClick.onRecyclerItemClick((RecyclerView) v.getParent(),position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return utils.StringUtils.isNull(mSelectDataStrs)?0:mSelectDataStrs.size();
    }

    public void setSelectDataStrs(ArrayList<String> mSelectDataStrs) {
        this.mSelectDataStrs = mSelectDataStrs;
    }

    public void setOnRecyclerViewItemClick(OnRecyclerViewItemClick onRecyclerViewItemClick) {
        mOnRecyclerViewItemClick = onRecyclerViewItemClick;
    }

    public void setSelectPos(int selectPos) {
        mSelectPos = selectPos;
    }

    public class SelectSportViewHolder extends RecyclerView.ViewHolder{
        public TextView mTvSportName;

        public SelectSportViewHolder(View itemView) {
            super(itemView);
            mTvSportName= (TextView) itemView.findViewById(R.id.tv_sport_name);
        }
    }
}
